/*
* Copyright 2004-2005 mbsx@seznam.cz
* All Rights Reserved.
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Drawing.Printing;
using System.IO;

namespace DeskNotes
{
	/// <summary>
	/// The form is main object which is loaded by application.
	/// It contains TaskBar notification icon and serves as handler for users
	/// action from notify icon pop up menu.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		//delegate void PrintInBackgroundDelegate();

		private delegate void ShowNotes();
        internal delegate void CallWhenShown();

		//private ShowNotes showDeskNotes;
		private System.Windows.Forms.NotifyIcon ni;
		private System.Windows.Forms.Label label1;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.ContextMenu statusBarMenu;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.SaveFileDialog newDataSet;
		private System.Windows.Forms.OpenFileDialog openDataSet;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.MenuItem menuOptions;
		private System.Windows.Forms.MenuItem menuNew;
		private System.Windows.Forms.MenuItem menuShowAll;
		private System.Windows.Forms.MenuItem menuItem3;
		internal DeskNotes deskNotes;
		//NotePrintDocument myDoc;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem5;
		private System.Windows.Forms.Button btnClose;
		private int lastMenuIndex = 0;
		private System.Windows.Forms.Label lblVersion;
		private System.Windows.Forms.MenuItem menuPageSetup;
		private System.Windows.Forms.MenuItem menuPrintAll;
		private System.Windows.Forms.MenuItem menuItem8;
		private System.Windows.Forms.PageSetupDialog pageSetupDialog;
		private System.Windows.Forms.MenuItem menuHideAll;
		private System.Windows.Forms.MenuItem menuItem7;
		private System.Windows.Forms.MenuItem menuPrintPreview;
		private System.Windows.Forms.MenuItem menuArchive;
		//private bool aboutShowed = false;
        private System.Windows.Forms.Label lblNET;
		internal ArchiveForm archiveForm = null;
        private MenuItem menuSyncAll;
        private ContextMenuStrip mainMenu;
        private ToolStripMenuItem newStripMenuItem;
        private ToolStripMenuItem showAllStripMenuItem;
        private ToolStripMenuItem synchronizeAllStripMenuItem;
        private ToolStripMenuItem hideAllStripMenuItem;
        private ToolStripMenuItem settingsStripMenuItem;
        private ToolStripMenuItem archiveStripMenuItem;
        private ToolStripMenuItem printPreviewStripMenuItem;
        private ToolStripMenuItem pageSetupStripMenuItem;
        private ToolStripMenuItem aboutStripMenuItem;
        private ToolStripMenuItem printAllStripMenuItem;
        private ToolStripMenuItem exitStripMenuItem;
        private ToolStripSeparator toolStripSeparator1;
        private ToolStripSeparator toolStripSeparator2;
        private ToolStripSeparator toolStripSeparator3;
        private ToolStripSeparator toolStripSeparator4;
        private ToolStripSeparator toolStripSeparator5;
        private ToolStripSeparator toolStripSeparator6;
        private ContextMenuStrip menuCopyInfo;
        private ToolStripMenuItem copyInfoStripMenuItem;
    
	
		
		public MainForm()
		{
			deskNotes = new DeskNotes();
			Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Properties.Settings.Default.Culture);
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//showDeskNotes = new ShowNotes(ShowAllDeskNotes);
			lastMenuIndex = statusBarMenu.MenuItems.Count;
			Application.ApplicationExit += new EventHandler(this.OnApplicationExit);
            // get version info
            System.Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            string ver = string.Format(MainResource.GetString("VERSION_INFO"), version.Major, version.Minor,
                version.Revision, version.Build);
            lblVersion.Text = ver;

            System.Version clrVersion = System.Environment.Version;
            string clr = string.Format(MainResource.GetString("CLR_VERSION_INFO"), clrVersion.Major, clrVersion.Minor, clrVersion.Revision, clrVersion.Build);
            lblNET.Text = clr;
            this.Visible = false;
            //initialize splash screen
            /*
            splashScreen = new Splash(ver, clr);
            splashScreen.Show(this);
            Thread.Sleep(500);
             */
 		}

        private void OnLoad(object sender, System.EventArgs e)
        {
            //Console.WriteLine("MainForm.Load called");
            try
            {
                this.Visible = false;

                // Read settings and data in async thread this allows main form to be fully painted.
                //this.BeginInvoke(new ShowNotes(RunWhenLoaded));
                RunWhenLoaded();
                //Thread.Sleep(1000);
            }
            catch (Exception ex)
            {// catch any exception which can happen when working with DataSet.
                MessageBox.Show(this, MainResource.GetString("APP_ERROR") + ex.Message, MainResource.GetString("APP_TITLE"),
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

		/// <summary>
		/// Thread procedure used to perform data file initialization and data reading.
		/// The thread is started from Form's OnLoad event.
		/// Method performs check is data file already exists. It either reads data from file or
		/// creates a new one which is specified by user.
		/// </summary>
		public void RunWhenLoaded()
		{
			try 
			{
				bool initiated = true;
				switch (deskNotes.UsageStyle){
                    case DeskNotes.UsageType.FirstTime:
                        // Creates new files, ask for their names.
					    initiated = InitializeDataFile();
                        break;
                    case DeskNotes.UsageType.OldVersionFound:
                        // Copy old data into new files.
                        initiated = CopyOldDataFiles();
                        break;
                    case DeskNotes.UsageType.Regular:
                        initiated = true;
                        break;
                }
                
				if (initiated)
				{
                    // Settings should be saved when user specified data files to be used.
                    Properties.Settings.Default.Save(); 
                    deskNotes.OpenDataSet();
                    deskNotes.ReadAllData();
					// call showdesknotes when preprocessing is done
					ShowAllDeskNotes();
                    this.ni.ShowBalloonTip(5000);
                }
				else
				{
					Application.Exit();
				}
			} 
			catch (Exception ex)
			{
				this.Hide();
				MessageBox.Show(this, MainResource.GetString("ERROR_READ_DATA") + ex.Message,
					MainResource.GetString("APP_TITLE"),
					MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}

       

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
            this.ni = new System.Windows.Forms.NotifyIcon(this.components);
            this.mainMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.newStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.showAllStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.synchronizeAllStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.hideAllStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
            this.settingsStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.archiveStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
            this.printPreviewStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.printAllStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.pageSetupStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
            this.aboutStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
            this.exitStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
            this.statusBarMenu = new System.Windows.Forms.ContextMenu();
            this.menuNew = new System.Windows.Forms.MenuItem();
            this.menuItem7 = new System.Windows.Forms.MenuItem();
            this.menuShowAll = new System.Windows.Forms.MenuItem();
            this.menuSyncAll = new System.Windows.Forms.MenuItem();
            this.menuHideAll = new System.Windows.Forms.MenuItem();
            this.menuItem3 = new System.Windows.Forms.MenuItem();
            this.menuOptions = new System.Windows.Forms.MenuItem();
            this.menuArchive = new System.Windows.Forms.MenuItem();
            this.menuItem4 = new System.Windows.Forms.MenuItem();
            this.menuPrintPreview = new System.Windows.Forms.MenuItem();
            this.menuPrintAll = new System.Windows.Forms.MenuItem();
            this.menuPageSetup = new System.Windows.Forms.MenuItem();
            this.menuItem8 = new System.Windows.Forms.MenuItem();
            this.menuItem5 = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.label1 = new System.Windows.Forms.Label();
            this.menuCopyInfo = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.copyInfoStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.newDataSet = new System.Windows.Forms.SaveFileDialog();
            this.openDataSet = new System.Windows.Forms.OpenFileDialog();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.lblVersion = new System.Windows.Forms.Label();
            this.btnClose = new System.Windows.Forms.Button();
            this.pageSetupDialog = new System.Windows.Forms.PageSetupDialog();
            this.lblNET = new System.Windows.Forms.Label();
            this.mainMenu.SuspendLayout();
            this.menuCopyInfo.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // ni
            // 
            this.ni.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
            resources.ApplyResources(this.ni, "ni");
            this.ni.ContextMenuStrip = this.mainMenu;
            this.ni.DoubleClick += new System.EventHandler(this.menuNew_Click);
            this.ni.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ni_MouseClick);
            // 
            // mainMenu
            // 
            this.mainMenu.AccessibleDescription = null;
            this.mainMenu.AccessibleName = null;
            resources.ApplyResources(this.mainMenu, "mainMenu");
            this.mainMenu.BackgroundImage = null;
            this.mainMenu.Font = null;
            this.mainMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.newStripMenuItem,
            this.toolStripSeparator1,
            this.showAllStripMenuItem,
            this.synchronizeAllStripMenuItem,
            this.hideAllStripMenuItem,
            this.toolStripSeparator2,
            this.settingsStripMenuItem,
            this.archiveStripMenuItem,
            this.toolStripSeparator3,
            this.printPreviewStripMenuItem,
            this.printAllStripMenuItem,
            this.pageSetupStripMenuItem,
            this.toolStripSeparator4,
            this.aboutStripMenuItem,
            this.toolStripSeparator5,
            this.exitStripMenuItem,
            this.toolStripSeparator6});
            this.mainMenu.Name = "contextMenuStrip1";
            this.mainMenu.Opening += new System.ComponentModel.CancelEventHandler(this.mainMenu_Opening);
            // 
            // newStripMenuItem
            // 
            this.newStripMenuItem.AccessibleDescription = null;
            this.newStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.newStripMenuItem, "newStripMenuItem");
            this.newStripMenuItem.BackgroundImage = null;
            this.newStripMenuItem.Name = "newStripMenuItem";
            this.newStripMenuItem.ShortcutKeyDisplayString = null;
            this.newStripMenuItem.Click += new System.EventHandler(this.menuNew_Click);
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.AccessibleDescription = null;
            this.toolStripSeparator1.AccessibleName = null;
            resources.ApplyResources(this.toolStripSeparator1, "toolStripSeparator1");
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            // 
            // showAllStripMenuItem
            // 
            this.showAllStripMenuItem.AccessibleDescription = null;
            this.showAllStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.showAllStripMenuItem, "showAllStripMenuItem");
            this.showAllStripMenuItem.BackgroundImage = null;
            this.showAllStripMenuItem.Name = "showAllStripMenuItem";
            this.showAllStripMenuItem.ShortcutKeyDisplayString = null;
            this.showAllStripMenuItem.Click += new System.EventHandler(this.menuShowAll_Click);
            // 
            // synchronizeAllStripMenuItem
            // 
            this.synchronizeAllStripMenuItem.AccessibleDescription = null;
            this.synchronizeAllStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.synchronizeAllStripMenuItem, "synchronizeAllStripMenuItem");
            this.synchronizeAllStripMenuItem.BackgroundImage = null;
            this.synchronizeAllStripMenuItem.Name = "synchronizeAllStripMenuItem";
            this.synchronizeAllStripMenuItem.ShortcutKeyDisplayString = null;
            this.synchronizeAllStripMenuItem.Click += new System.EventHandler(this.menuSyncAll_Click);
            // 
            // hideAllStripMenuItem
            // 
            this.hideAllStripMenuItem.AccessibleDescription = null;
            this.hideAllStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.hideAllStripMenuItem, "hideAllStripMenuItem");
            this.hideAllStripMenuItem.BackgroundImage = null;
            this.hideAllStripMenuItem.Name = "hideAllStripMenuItem";
            this.hideAllStripMenuItem.ShortcutKeyDisplayString = null;
            this.hideAllStripMenuItem.Click += new System.EventHandler(this.menuHideAll_Click);
            // 
            // toolStripSeparator2
            // 
            this.toolStripSeparator2.AccessibleDescription = null;
            this.toolStripSeparator2.AccessibleName = null;
            resources.ApplyResources(this.toolStripSeparator2, "toolStripSeparator2");
            this.toolStripSeparator2.Name = "toolStripSeparator2";
            // 
            // settingsStripMenuItem
            // 
            this.settingsStripMenuItem.AccessibleDescription = null;
            this.settingsStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.settingsStripMenuItem, "settingsStripMenuItem");
            this.settingsStripMenuItem.BackgroundImage = null;
            this.settingsStripMenuItem.Name = "settingsStripMenuItem";
            this.settingsStripMenuItem.ShortcutKeyDisplayString = null;
            this.settingsStripMenuItem.Click += new System.EventHandler(this.menuOptions_Click);
            // 
            // archiveStripMenuItem
            // 
            this.archiveStripMenuItem.AccessibleDescription = null;
            this.archiveStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.archiveStripMenuItem, "archiveStripMenuItem");
            this.archiveStripMenuItem.BackgroundImage = null;
            this.archiveStripMenuItem.Name = "archiveStripMenuItem";
            this.archiveStripMenuItem.ShortcutKeyDisplayString = null;
            this.archiveStripMenuItem.Click += new System.EventHandler(this.menuArchive_Click);
            // 
            // toolStripSeparator3
            // 
            this.toolStripSeparator3.AccessibleDescription = null;
            this.toolStripSeparator3.AccessibleName = null;
            resources.ApplyResources(this.toolStripSeparator3, "toolStripSeparator3");
            this.toolStripSeparator3.Name = "toolStripSeparator3";
            // 
            // printPreviewStripMenuItem
            // 
            this.printPreviewStripMenuItem.AccessibleDescription = null;
            this.printPreviewStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.printPreviewStripMenuItem, "printPreviewStripMenuItem");
            this.printPreviewStripMenuItem.BackgroundImage = null;
            this.printPreviewStripMenuItem.Name = "printPreviewStripMenuItem";
            this.printPreviewStripMenuItem.ShortcutKeyDisplayString = null;
            this.printPreviewStripMenuItem.Click += new System.EventHandler(this.menuPrintPreview_Click);
            // 
            // printAllStripMenuItem
            // 
            this.printAllStripMenuItem.AccessibleDescription = null;
            this.printAllStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.printAllStripMenuItem, "printAllStripMenuItem");
            this.printAllStripMenuItem.BackgroundImage = null;
            this.printAllStripMenuItem.Name = "printAllStripMenuItem";
            this.printAllStripMenuItem.ShortcutKeyDisplayString = null;
            this.printAllStripMenuItem.Click += new System.EventHandler(this.menuPrintAll_Click);
            // 
            // pageSetupStripMenuItem
            // 
            this.pageSetupStripMenuItem.AccessibleDescription = null;
            this.pageSetupStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.pageSetupStripMenuItem, "pageSetupStripMenuItem");
            this.pageSetupStripMenuItem.BackgroundImage = null;
            this.pageSetupStripMenuItem.Name = "pageSetupStripMenuItem";
            this.pageSetupStripMenuItem.ShortcutKeyDisplayString = null;
            this.pageSetupStripMenuItem.Click += new System.EventHandler(this.menuPageSetup_Click);
            // 
            // toolStripSeparator4
            // 
            this.toolStripSeparator4.AccessibleDescription = null;
            this.toolStripSeparator4.AccessibleName = null;
            resources.ApplyResources(this.toolStripSeparator4, "toolStripSeparator4");
            this.toolStripSeparator4.Name = "toolStripSeparator4";
            // 
            // aboutStripMenuItem
            // 
            this.aboutStripMenuItem.AccessibleDescription = null;
            this.aboutStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.aboutStripMenuItem, "aboutStripMenuItem");
            this.aboutStripMenuItem.BackgroundImage = null;
            this.aboutStripMenuItem.Name = "aboutStripMenuItem";
            this.aboutStripMenuItem.ShortcutKeyDisplayString = null;
            this.aboutStripMenuItem.Click += new System.EventHandler(this.menuAbout_Click);
            // 
            // toolStripSeparator5
            // 
            this.toolStripSeparator5.AccessibleDescription = null;
            this.toolStripSeparator5.AccessibleName = null;
            resources.ApplyResources(this.toolStripSeparator5, "toolStripSeparator5");
            this.toolStripSeparator5.Name = "toolStripSeparator5";
            // 
            // exitStripMenuItem
            // 
            this.exitStripMenuItem.AccessibleDescription = null;
            this.exitStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.exitStripMenuItem, "exitStripMenuItem");
            this.exitStripMenuItem.BackgroundImage = null;
            this.exitStripMenuItem.Name = "exitStripMenuItem";
            this.exitStripMenuItem.ShortcutKeyDisplayString = null;
            this.exitStripMenuItem.Click += new System.EventHandler(this.ExitSelected);
            // 
            // toolStripSeparator6
            // 
            this.toolStripSeparator6.AccessibleDescription = null;
            this.toolStripSeparator6.AccessibleName = null;
            resources.ApplyResources(this.toolStripSeparator6, "toolStripSeparator6");
            this.toolStripSeparator6.Name = "toolStripSeparator6";
            // 
            // statusBarMenu
            // 
            this.statusBarMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuNew,
            this.menuItem7,
            this.menuShowAll,
            this.menuSyncAll,
            this.menuHideAll,
            this.menuItem3,
            this.menuOptions,
            this.menuArchive,
            this.menuItem4,
            this.menuPrintPreview,
            this.menuPrintAll,
            this.menuPageSetup,
            this.menuItem8,
            this.menuItem5,
            this.menuItem2,
            this.menuItem1});
            resources.ApplyResources(this.statusBarMenu, "statusBarMenu");
            this.statusBarMenu.Popup += new System.EventHandler(this.statusBarMenu_Popup);
            // 
            // menuNew
            // 
            this.menuNew.DefaultItem = true;
            resources.ApplyResources(this.menuNew, "menuNew");
            this.menuNew.Index = 0;
            this.menuNew.Click += new System.EventHandler(this.menuNew_Click);
            // 
            // menuItem7
            // 
            resources.ApplyResources(this.menuItem7, "menuItem7");
            this.menuItem7.Index = 1;
            // 
            // menuShowAll
            // 
            resources.ApplyResources(this.menuShowAll, "menuShowAll");
            this.menuShowAll.Index = 2;
            this.menuShowAll.Click += new System.EventHandler(this.menuShowAll_Click);
            // 
            // menuSyncAll
            // 
            resources.ApplyResources(this.menuSyncAll, "menuSyncAll");
            this.menuSyncAll.Index = 3;
            this.menuSyncAll.Click += new System.EventHandler(this.menuSyncAll_Click);
            // 
            // menuHideAll
            // 
            resources.ApplyResources(this.menuHideAll, "menuHideAll");
            this.menuHideAll.Index = 4;
            this.menuHideAll.Click += new System.EventHandler(this.menuHideAll_Click);
            // 
            // menuItem3
            // 
            resources.ApplyResources(this.menuItem3, "menuItem3");
            this.menuItem3.Index = 5;
            // 
            // menuOptions
            // 
            resources.ApplyResources(this.menuOptions, "menuOptions");
            this.menuOptions.Index = 6;
            this.menuOptions.Click += new System.EventHandler(this.menuOptions_Click);
            // 
            // menuArchive
            // 
            resources.ApplyResources(this.menuArchive, "menuArchive");
            this.menuArchive.Index = 7;
            this.menuArchive.Click += new System.EventHandler(this.menuArchive_Click);
            // 
            // menuItem4
            // 
            resources.ApplyResources(this.menuItem4, "menuItem4");
            this.menuItem4.Index = 8;
            // 
            // menuPrintPreview
            // 
            resources.ApplyResources(this.menuPrintPreview, "menuPrintPreview");
            this.menuPrintPreview.Index = 9;
            this.menuPrintPreview.Click += new System.EventHandler(this.menuPrintPreview_Click);
            // 
            // menuPrintAll
            // 
            resources.ApplyResources(this.menuPrintAll, "menuPrintAll");
            this.menuPrintAll.Index = 10;
            this.menuPrintAll.Click += new System.EventHandler(this.menuPrintAll_Click);
            // 
            // menuPageSetup
            // 
            resources.ApplyResources(this.menuPageSetup, "menuPageSetup");
            this.menuPageSetup.Index = 11;
            this.menuPageSetup.Click += new System.EventHandler(this.menuPageSetup_Click);
            // 
            // menuItem8
            // 
            resources.ApplyResources(this.menuItem8, "menuItem8");
            this.menuItem8.Index = 12;
            // 
            // menuItem5
            // 
            resources.ApplyResources(this.menuItem5, "menuItem5");
            this.menuItem5.Index = 13;
            this.menuItem5.Click += new System.EventHandler(this.menuAbout_Click);
            // 
            // menuItem2
            // 
            resources.ApplyResources(this.menuItem2, "menuItem2");
            this.menuItem2.Index = 14;
            // 
            // menuItem1
            // 
            resources.ApplyResources(this.menuItem1, "menuItem1");
            this.menuItem1.Index = 15;
            this.menuItem1.Select += new System.EventHandler(this.menuItem1_Select);
            this.menuItem1.Click += new System.EventHandler(this.ExitSelected);
            // 
            // label1
            // 
            this.label1.AccessibleDescription = null;
            this.label1.AccessibleName = null;
            resources.ApplyResources(this.label1, "label1");
            this.label1.ContextMenuStrip = this.menuCopyInfo;
            this.label1.Name = "label1";
            // 
            // menuCopyInfo
            // 
            this.menuCopyInfo.AccessibleDescription = null;
            this.menuCopyInfo.AccessibleName = null;
            resources.ApplyResources(this.menuCopyInfo, "menuCopyInfo");
            this.menuCopyInfo.BackgroundImage = null;
            this.menuCopyInfo.Font = null;
            this.menuCopyInfo.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.copyInfoStripMenuItem});
            this.menuCopyInfo.Name = "menuCopyInfo";
            // 
            // copyInfoStripMenuItem
            // 
            this.copyInfoStripMenuItem.AccessibleDescription = null;
            this.copyInfoStripMenuItem.AccessibleName = null;
            resources.ApplyResources(this.copyInfoStripMenuItem, "copyInfoStripMenuItem");
            this.copyInfoStripMenuItem.BackgroundImage = null;
            this.copyInfoStripMenuItem.Name = "copyInfoStripMenuItem";
            this.copyInfoStripMenuItem.ShortcutKeyDisplayString = null;
            this.copyInfoStripMenuItem.Click += new System.EventHandler(this.menuCopy_Click);
            // 
            // newDataSet
            // 
            this.newDataSet.DefaultExt = "xml";
            this.newDataSet.FileName = "Notes.xml";
            resources.ApplyResources(this.newDataSet, "newDataSet");
            // 
            // openDataSet
            // 
            this.openDataSet.DefaultExt = "xml";
            this.openDataSet.FileName = "Notes.xml";
            resources.ApplyResources(this.openDataSet, "openDataSet");
            // 
            // pictureBox1
            // 
            this.pictureBox1.AccessibleDescription = null;
            this.pictureBox1.AccessibleName = null;
            resources.ApplyResources(this.pictureBox1, "pictureBox1");
            this.pictureBox1.BackgroundImage = null;
            this.pictureBox1.ContextMenuStrip = this.menuCopyInfo;
            this.pictureBox1.Font = null;
            this.pictureBox1.ImageLocation = null;
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.TabStop = false;
            // 
            // lblVersion
            // 
            this.lblVersion.AccessibleDescription = null;
            this.lblVersion.AccessibleName = null;
            resources.ApplyResources(this.lblVersion, "lblVersion");
            this.lblVersion.ContextMenuStrip = this.menuCopyInfo;
            this.lblVersion.Name = "lblVersion";
            // 
            // btnClose
            // 
            this.btnClose.AccessibleDescription = null;
            this.btnClose.AccessibleName = null;
            resources.ApplyResources(this.btnClose, "btnClose");
            this.btnClose.BackgroundImage = null;
            this.btnClose.Font = null;
            this.btnClose.Name = "btnClose";
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // pageSetupDialog
            // 
            this.pageSetupDialog.MinMargins = new System.Drawing.Printing.Margins(10, 10, 10, 10);
            // 
            // lblNET
            // 
            this.lblNET.AccessibleDescription = null;
            this.lblNET.AccessibleName = null;
            resources.ApplyResources(this.lblNET, "lblNET");
            this.lblNET.ContextMenuStrip = this.menuCopyInfo;
            this.lblNET.Name = "lblNET";
            // 
            // MainForm
            // 
            this.AccessibleDescription = null;
            this.AccessibleName = null;
            resources.ApplyResources(this, "$this");
            this.BackgroundImage = null;
            this.ContextMenuStrip = this.menuCopyInfo;
            this.ControlBox = false;
            this.Controls.Add(this.lblNET);
            this.Controls.Add(this.btnClose);
            this.Controls.Add(this.lblVersion);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.label1);
            this.Font = null;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "MainForm";
            this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
            this.Load += new System.EventHandler(this.OnLoad);
            this.mainMenu.ResumeLayout(false);
            this.menuCopyInfo.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion
		
		[STAThread]
		public static void Main(string[] args)
		{
			if (args.Length > 0)
			{ //Pass debug regedit key into desknotes.
				DeskNotes.Debug = args[0];
			}
            //debug windows information
            Console.WriteLine("SM_CXBORDER: {0}", WinImports.GetSystemMetrics(WinImports.SM_CXBORDER));
            Console.WriteLine("SM_CXEDGE: {0}", WinImports.GetSystemMetrics(WinImports.SM_CXEDGE));
            Console.WriteLine("SM_CXFIXEDFRAME: {0}", WinImports.GetSystemMetrics(WinImports.SM_CXFIXEDFRAME));
            Console.WriteLine("SM_CXFOCUSBORDER: {0}", WinImports.GetSystemMetrics(WinImports.SM_CXFOCUSBORDER));
            Console.WriteLine("SM_CXSIZEFRAME: {0}", WinImports.GetSystemMetrics(WinImports.SM_CXSIZEFRAME));

			// create main window handler which is hidden.
			Application.Run(new MainForm());
			
		}

		/// <summary>
		/// When context menu Exit is selected then initiate application exit
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		public void ExitSelected(object sender, System.EventArgs e)
		{
			//deskNotes.Exit();
			Application.Exit();
		}
		/// <summary>
		/// Saves all settings and archive and removes tray icon when application exits.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnApplicationExit(object sender, EventArgs e) 
		{
			deskNotes.SaveAll();
            try
            {
                ni.Visible = false;
            }
            catch (Exception exc) { //do nothing
            }
		}


		
		

		/// <summary>
		/// Method handles user input re data file to be used or created. It is called when Registry does not 
		/// contain DataFile value.
		/// It offers three options:
		/// 1st - create a new file
		/// 2nd - choose an existing one, but missing for some reason
		/// 3rd - cancel application startup and quit app.
		/// </summary>
		/// <returns>true when data file was selected or new created, otherwise false.</returns>
	
		private bool InitializeDataFile()
		{
			try 
			{
                Properties.Settings settings = Properties.Settings.Default;
                SetDataStorageDlg dataStoreDlg = new SetDataStorageDlg();
                dataStoreDlg.storageControl.CheckFileExists = false;
                if ("" == settings.ArchiveFile)
                    dataStoreDlg.storageControl.ArchiveFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + DeskNotes.DEFAULT_ARCHIVE;
                else
                    dataStoreDlg.storageControl.ArchiveFileName = settings.ArchiveFile;
                if ("" == settings.DataFile)
                    dataStoreDlg.storageControl.DataFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + DeskNotes.DEFAULT_DATA;
                else
                    dataStoreDlg.storageControl.DataFileName = settings.DataFile;
                
               
                DialogResult res = dataStoreDlg.ShowDialog(this);

                if (DialogResult.OK == res)
                {

                    // Set archive file name
                    if (dataStoreDlg.storageControl.ArchiveFileName != settings.ArchiveFile)
                    {
                        if (deskNotes.CreateArchiveFile(dataStoreDlg.storageControl.ArchiveFileName))
                            Properties.Settings.Default.ArchiveFile = dataStoreDlg.storageControl.ArchiveFileName;
                        else
                            return false;
                    }

                    // check data file filename
                    if (dataStoreDlg.storageControl.DataFileName != settings.DataFile)
                    {
                        // create new datafile according to entered filename
                        if (deskNotes.CreateNewDataSet(dataStoreDlg.storageControl.DataFileName))
                            settings.DataFile = dataStoreDlg.storageControl.DataFileName;
                        else
                            return false;
                    }
                    else if ("" == dataStoreDlg.storageControl.DataFileName)
                    {  // If data file is not set then it is bad and app cannot be really started.
                        return false;
                    }
                    return true;
                }
                else
                {   // Create default data & archive files and save them in settings. 
                    // Upon next start DN will open Data specified here.
                    Properties.Settings.Default.ArchiveFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + DeskNotes.DEFAULT_ARCHIVE;
                    Properties.Settings.Default.DataFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + DeskNotes.DEFAULT_DATA;
                    deskNotes.CreateNewDataSet(Properties.Settings.Default.DataFile);
                    Properties.Settings.Default.ShowInitialDeskNote = false;
                    Properties.Settings.Default.Save();
                    return false;
                }
			} 
			catch (Exception ex)
			{// catch any exception which can happen when working with DataSet.
				MessageBox.Show(this, Resources.AppResource.ERROR_INIT_DATA + ex.Message, Resources.AppResource.APP_TITLE,
					MessageBoxButtons.OK, MessageBoxIcon.Error);
				return false;
			} 
		}
        /// <summary>
        /// Asks user to provide new file names where to copy existing old DeskNotes data.
        /// If new names are same as old one then it overwrites them after user confirmation.
        /// </summary>
        /// <returns>True when files were copied or existing files have to be used.</returns>
        private bool CopyOldDataFiles()
        {
            try {
                Properties.Settings settings = Properties.Settings.Default;
                UpgradeDataStorageDlg dlg = new UpgradeDataStorageDlg();
                
                dlg.OldDataFile = settings.DataFile;
                dlg.OldArchiveFile = settings.ArchiveFile;
                dlg.storageControl.CheckFileExists = false;
                dlg.storageControl.OpenDirectory = true;

                if (DialogResult.OK == dlg.ShowDialog())
                {
                    //copy files to new one
                    // TODO - more control should be done for existing files and as to overwrite.
                    File.Copy(settings.DataFile, dlg.storageControl.DataFileName, true);
                    settings.DataFile = dlg.storageControl.DataFileName;
                    if ("" != settings.ArchiveFile)
                    {
                        File.Copy(settings.ArchiveFile, dlg.storageControl.ArchiveFileName, true);
                        settings.ArchiveFile = dlg.storageControl.ArchiveFileName;
                    }
                    return true;
                }
                else
                { // Cancel pressed. Then ask if user wants to overwrite existing data files.
                    string text = string.Format(Resources.AppResource.ConfirmOverwriteDataFiles, settings.DataFile, settings.ArchiveFile);
                    if (DialogResult.Yes == MessageBox.Show(this, text, Resources.AppResource.APP_TITLE, 
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                        
                        return true;
                    else
                    {   // User does not want to overwrite existing data files. 
                        // Then it will exit and unset datafiles in config.
                        settings.DataFile = "";
                        settings.ArchiveFile = "";
                        return false;
                    }
                }
            }
            catch (Exception ex)
			{// catch any exception which can happen when working with DataSet.
				MessageBox.Show(this, Resources.AppResource.ERROR_INIT_DATA + ex.Message, Resources.AppResource.APP_TITLE,
					MessageBoxButtons.OK, MessageBoxIcon.Error);
				return false;
			} 
        }
		/// <summary>
		/// Method is used to display desk notes when background thread is done
		/// This is used as a workaround because forms created in a different than
		/// main form thread are destroyed when the thread ends.
		/// </summary>
		
		//private void OnVisibleChanged(object sender, System.EventArgs e)
		private void ShowAllDeskNotes()
		{
			// simply call DeskNotes show all notes
            deskNotes.ShowDeskNotes();
            // Close splash when all notes were shown.
            //splashScreen.CloseMe();
		}


		private void menuOptions_Click(object sender, System.EventArgs e)
		{
            Properties.Settings config = Properties.Settings.Default;
            //config.Reload();

			SettingsDialog settings = new SettingsDialog();
			settings.btnBackground.BackColor = config.BackgroundColor;
			settings.btnText.BackColor = config.TextColor;
			settings.lblFont.Font = config.Font;
			settings.chkInsertOnlyDate.Checked = config.InsertOnlyDate;
			settings.chkSound.Checked = deskNotes.PlaySound;
			settings.comboLanguage.SelectedItem = new System.Globalization.CultureInfo(config.Culture).NativeName;
            settings.dataStorage.DataFileName = config.DataFile;
            settings.dataStorage.ArchiveFileName = config.ArchiveFile;
            settings.chkRemoveOutlook.Checked = config.RemoveInOutlook;
            
			if (config.OriginalLook)
				settings.rbOwn.Checked = true;
			else
				settings.rbSystem.Checked = true;
			if (config.DragDropToArchive)
				settings.rbDragDrop.Checked = true;
			else
				settings.rbArchive.Checked = true;
			
			if (deskNotes.PlaySound)
				settings.txtSound.Text = config.SoundFile;
			else 
			{
				settings.txtSound.Enabled = false;
				settings.btnSound.Enabled = false;
			}
			if (DialogResult.OK == settings.ShowDialog(this))
			{
				if (settings.btnBackground.BackColor != config.BackgroundColor)
					config.BackgroundColor = settings.btnBackground.BackColor;
				if (settings.btnText.BackColor != config.TextColor)
					config.TextColor = settings.btnText.BackColor;
				if (settings.lblFont.Font != config.Font)
					config.Font = settings.lblFont.Font;

                if (config.InsertOnlyDate != settings.chkInsertOnlyDate.Checked)
                    config.InsertOnlyDate = settings.chkInsertOnlyDate.Checked;

                if (config.DragDropToArchive != settings.rbDragDrop.Checked)
                    config.DragDropToArchive = settings.rbDragDrop.Checked;

                if (config.OriginalLook != settings.rbOwn.Checked)
                    config.OriginalLook = settings.rbOwn.Checked;

                if (config.RemoveInOutlook != settings.chkRemoveOutlook.Checked)
                    config.RemoveInOutlook = settings.chkRemoveOutlook.Checked;
				
				config.SoundFile = (settings.chkSound.Checked) && (config.SoundFile != settings.txtSound.Text) ? 
					settings.txtSound.Text : null;
				if (0 == settings.comboLanguage.SelectedIndex)
					config.Culture = "en-US";
				else
					config.Culture = "cs-CZ";

                // Settings requiring restart of application.
                bool restart = false;
                
                // If following settings changed then DeskNotes has to be restarted.
                if ((settings.dataStorage.DataFileName != config.DataFile) &&
                    (settings.dataStorage.DataFileName != ""))
                    restart = true;
                if ((settings.dataStorage.ArchiveFileName != config.ArchiveFile) &&
                    (settings.dataStorage.ArchiveFileName != ""))
                    restart = true;
                

                if (restart)
                {
                    if (DialogResult.Yes == MessageBox.Show(Resources.AppResource.APP_RESTART, Resources.AppResource.APP_TITLE,
                            MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
                    {
                        deskNotes.Save();
                        deskNotes.SaveArchive();
                        config.DataFile = settings.dataStorage.DataFileName;
                        config.ArchiveFile = settings.dataStorage.ArchiveFileName;
                        config.Save();
                        Application.ApplicationExit -= this.OnApplicationExit;
                        // Restart() causes process to hold (lock) Settings file if product is running inside debugger.
                        // This is OK when run outside of debugger then settings are not locked and they are correctly read
                        // during subsequent start.
                        Application.Restart(); 
                        return;
                    }
                }
			}
            config.Save();
		}

		/// <summary>
		/// Method creates a new note in a default position.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuNew_Click(object sender, System.EventArgs e)
		{
			deskNotes.CreateNewNote(MainResource.GetString("FIRST_NOTE"), Note.DefaultPosition);
		}

		/// <summary>
		/// Brings all desk notes to front of the user above all other 
		/// windows displayed on desktop.
		/// </summary
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuShowAll_Click(object sender, System.EventArgs e)
		{
			IEnumerator myEnum = deskNotes.GetEnumerator();
			deskNotes.ShowingAllNotes = true;
			while (myEnum.MoveNext())
			{
				Note n = (Note) myEnum.Current;
				//create forms for hidden DeskNotes
				if (n.Hidden)
				{
					NoteForm nf = new NoteForm();
					nf.NoteData = n;
					nf.Show();
					n.Hidden = false;
				} else
					n.MyForm.Activate();
			}
			// Top most note is reset when note is added. It needs to
			// be set again after creation.
			deskNotes.ConfirmTopMost();
			deskNotes.ShowingAllNotes = false;
		}

		/// <summary>
		/// Hides all notes currently visible
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuHideAll_Click(object sender, System.EventArgs e)
		{
			IEnumerator myEnum = deskNotes.GetEnumerator();
			while (myEnum.MoveNext())
			{
				Note n = (Note) myEnum.Current;
				//create forms for hidden DeskNotes
				n.Hidden = true;
			}
		}

        private void ni_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                IEnumerator myEnum = deskNotes.GetEnumerator();
                while (myEnum.MoveNext())
                {
                    Note n = (Note)myEnum.Current;
                    if (!n.Hidden)
                        n.MyForm.Activate();
                }
            }
        }
		private void trayShowVisible(object sender, System.EventArgs e)
		{
			IEnumerator myEnum = deskNotes.GetEnumerator();
			while (myEnum.MoveNext())
			{
				Note n = (Note) myEnum.Current;
				if (!n.Hidden)
					n.MyForm.Activate();
			}
		}
        /// <summary>
        ///  Synchronizes all DeskNotes with their Outlook copies
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuSyncAll_Click(object sender, EventArgs e)
        {
            IEnumerator myEnum = deskNotes.GetEnumerator();
            SynchronizationConflictDlg.Result result, nextResult = SynchronizationConflictDlg.Result.SyncAll;
            try
            {
                while (myEnum.MoveNext())
                {
                    Note n = (Note)myEnum.Current;
                    if (null != n.OutlookEntryID)
                    {
                        result = n.SynchronizeOutlook(this, ref nextResult);
                        if (SynchronizationConflictDlg.Result.Cancel == nextResult)
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Show error dialog for Outlook integration
                MessageBox.Show(Resources.AppResource.OutlookError + ex.Message, Resources.AppResource.APP_TITLE,
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

		/// <summary>
		/// When menu is about to popup it gets a list of desknotes and displays them
		/// above action menu items.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void statusBarMenu_Popup(object sender, System.EventArgs e)
		{
			// remove menu items representing desknotes 
			int currentMenuCount = statusBarMenu.MenuItems.Count;
			for(int i = currentMenuCount; i > lastMenuIndex; i--)
			{
				statusBarMenu.MenuItems.RemoveAt(i-1);
			}
			//add menu items representing desknotes
			if (deskNotes.Count == 0)
				return;
			
			int count = lastMenuIndex;
			statusBarMenu.MenuItems.Add(count++,new MenuItem("-"));
			
			IEnumerator myEnum = deskNotes.GetEnumerator();
			while(myEnum.MoveNext())
			{
				Note n = (Note) myEnum.Current;
				// remove new line break from text before it is menu item. 
				// "\n" is displayed as square in the menu.
                string menuText = n.MyForm.TextEx;
				menuText = menuText.Length > 20 ? menuText.Substring(0,17) + "..." : menuText;
				menuText = menuText.Replace( "\n", " ");
				MenuItem mi = new MenuItem(menuText, new EventHandler(n.MyForm.ShowMeIndirectly));
				statusBarMenu.MenuItems.Add(mi);				
			}
		}

		/// <summary>
		/// Display MainForm like About dialog box.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuAbout_Click(object sender, System.EventArgs e)
		{
			this.Visible = true;
            this.WindowState = FormWindowState.Normal;
		}

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Visible = false;
		}
		/// <summary>
		/// Shows standard Page setup dialog and saves page settings into
		/// DeskNotes.pageSettings property for later use when printing.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuPageSetup_Click(object sender, System.EventArgs e)
		{
			try 
			{
				pageSetupDialog.PageSettings = deskNotes.DisplayedPageSettings;
				//System.Console.WriteLine("Margins: {0},{1},{2},{3}",deskNotes.pageSettings.Margins.Left,
				//	deskNotes.pageSettings.Margins.Top, deskNotes.pageSettings.Margins.Right, deskNotes.pageSettings.Margins.Bottom);
			
				if (DialogResult.OK == pageSetupDialog.ShowDialog(this))
				{
					deskNotes.PageSettings = pageSetupDialog.PageSettings;
				//	System.Console.WriteLine("Margins: {0},{1},{2},{3}",deskNotes.pageSettings.Margins.Left,
				//		deskNotes.pageSettings.Margins.Top, deskNotes.pageSettings.Margins.Right, deskNotes.pageSettings.Margins.Bottom);

				}
			} 
			catch (InvalidPrinterException)
			{
				MessageBox.Show(this, MainResource.GetString("PRINTER_NOT_AVAILABLE"), MainResource.GetString("APP_TITLE"),
					MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
        
		private void menuPrintAll_Click(object sender, System.EventArgs e)
		{
			try 
			{
				Note[] notes = new Note[deskNotes.Count];
				deskNotes.CopyTo(notes);
				deskNotes.PrintNotes(notes, (ToolStripMenuItem) sender, printPreviewStripMenuItem);
			} 
			catch (InvalidPrinterException ex)
			{
				MessageBox.Show(this, string.Format(MainResource.GetString("PRINTER_NOT_AVAILABLE"), ex.Message),
					MainResource.GetString("APP_TITLE"), MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}

		

		private void menuPrintPreview_Click(object sender, System.EventArgs e)
		{
			try 
			{
				Note[] notes = new Note[deskNotes.Count];
				deskNotes.CopyTo(notes);
				PrintPreviewForm printPreview = new PrintPreviewForm(deskNotes, notes);
				printPreview.Show();
			} 
			catch (InvalidPrinterException ex)
			{
				MessageBox.Show(this, string.Format(MainResource.GetString("PRINTER_NOT_AVAILABLE"), ex.Message),
					MainResource.GetString("APP_TITLE"), MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}

		/// <summary>
		/// Opens ArchiveForm
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuArchive_Click(object sender, System.EventArgs e)
		{
			deskNotes.ShowingAllNotes = true;
			//Load archive into memory
			if (deskNotes.LoadArchive())
			{
				//If archive was loaded then open archive form
				if (null == archiveForm)
				{
					archiveForm = new ArchiveForm(deskNotes);
					archiveForm.Disposed += new EventHandler(archiveForm_Disposed);
				}
				
				archiveForm.Show();
			}
			deskNotes.ShowingAllNotes = false;
		}
		/// <summary>
		/// ArchiveForm is disposed set this class holder to null.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void archiveForm_Disposed(object sender, EventArgs e)
		{
			archiveForm = null;
		}

		private void ni_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (MouseButtons.Left == e.Button)
			{
				Console.WriteLine("Icon mouse down.");
				IEnumerator myEnum = deskNotes.GetEnumerator();
				while(myEnum.MoveNext())
				{
					Note n = (Note) myEnum.Current;
					n.MyForm.sendBack = false;
				}
			}
		}

		private void menuItem1_Select(object sender, System.EventArgs e)
		{
			WinImports.MessageBeep(WinImports.IconQuestion);
		}

		private void menuCopy_Click(object sender, System.EventArgs e)
		{
			System.Text.StringBuilder text = new System.Text.StringBuilder(150);
			text.Append("DeskNotes ");
			text.Append(lblVersion.Text);
			text.Append("\r\n");
			text.Append(lblNET.Text);
			text.Append("\r\n");
			text.Append(Environment.OSVersion);
			Clipboard.SetDataObject(text.ToString(),true);
		}

       

        private void mainMenu_Opening(object sender, CancelEventArgs e)
        {
            // remove menu items representing desknotes 
            int currentMenuCount = mainMenu.Items.Count;
            for (int i = currentMenuCount; i > lastMenuIndex; i--)
            {
                mainMenu.Items.RemoveAt(i - 1);
            }
            //add menu items representing desknotes
            if (deskNotes.Count == 0)
                return;

            int count = lastMenuIndex;
            mainMenu.Items.Add(new ToolStripSeparator());
            ToolStripMenuItem menuItem;
            IEnumerator myEnum = deskNotes.GetEnumerator();
            Bitmap icon = Properties.Resources.tray.ToBitmap();
            while (myEnum.MoveNext())
            {
                Note n = (Note)myEnum.Current;
                string tipText = n.MyForm.TextEx;
                string menuText = tipText.Length > 20 ? tipText.Substring(0, 17) + "..." : tipText;
                menuText = menuText.Replace("\n", " ");
                tipText = tipText.Length > 70 ? tipText.Substring(0, 67) + "..." : tipText;
                menuItem = new ToolStripMenuItem(menuText);
                menuItem.ToolTipText = tipText;
                menuItem.Image = icon;
                menuItem.Click += new EventHandler(n.MyForm.ShowMeIndirectly);
                mainMenu.Items.Add(menuItem);
                
            }
        }

        

       	
	}
}
